﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using KPIS.GERP.Models.Class;
using KPIS.GERP.Models.SYS.ViewModel;

namespace KPIS.GERP.WEB.GIMS.Class
{
	public static class GimsConfigReader
	{
        // มีไว้สำหรับอ่านค่าจาก WebConfig
		#region GIMS Config Strong Type Reader

		public static string SiteMenuXml
		{
			get { return GerpConfig.GetByEntryName("SiteMenuXml"); }
		}

		public static string LoginMainTitle
		{
			get { return GerpConfig.GetByEntryName("LoginMainTitle"); }
		}

		public static string LoginSubTitle
		{
			get { return GerpConfig.GetByEntryName("LoginSubTitle"); }
		}

		public static string LoginThirdTitle
		{
			get { return GerpConfig.GetByEntryName("LoginThirdTitle"); }
		}

		public static string LoginLogoPath
		{
			get { return GerpConfig.GetByEntryName("LoginLogoPath"); }
		}

		public static string GimsFileFolder
		{
			get { return GerpConfig.GetByEntryName("GimsFileFolder"); }
		}

		public static string SystemName
		{
			get { return GerpConfig.GetByEntryName("SystemName"); }
		}

		public static string TableCellIndexLimitChar
		{
			get { return GerpConfig.GetByEntryName("TableCellIndexLimitChar"); }
		}
        
		public static string ErrorLogWebGimsUrl
		{
			get { return HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + "/" + GerpConfig.GetByEntryName("ErrorLogWebGimsUrl"); }
		}
		public static string ErrorLogWebGamsUrl
		{
			get { return HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + "/" + GerpConfig.GetByEntryName("ErrorLogWebGamsUrl"); }
		}
		public static string ErrorLogWebGfmsUrl
		{
			get { return HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + "/" + GerpConfig.GetByEntryName("ErrorLogWebGfmsUrl"); }
		}
		public static string ErrorLogWcfEssUrl
		{
			get { return HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + "/" + GerpConfig.GetByEntryName("ErrorLogWcfEssUrl"); }
		}
		public static string ErrorLogWcfGbmsUrl
		{
			get { return HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + "/" + GerpConfig.GetByEntryName("ErrorLogWcfGbmsUrl"); }
		}
		public static string ErrorLogWcfGhrmsUrl
		{
			get { return HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + "/" + GerpConfig.GetByEntryName("ErrorLogWcfGhrmsUrl"); }
		}
		public static string ErrorLogWcfGimsUrl
		{
			get { return HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + "/" + GerpConfig.GetByEntryName("ErrorLogWcfGimsUrl"); }
		}
		public static string ErrorLogWcfSysUrl
		{
			get { return HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + "/" + GerpConfig.GetByEntryName("ErrorLogWcfSysUrl"); }
		}
		public static string EssSelectSystemPage
		{
			get { return HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + "/" + GerpConfig.GetByEntryName("EssSelectSystemPage"); }
		}

		public static string EssLoginPage
		{
			get { return HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + "/" + GerpConfig.GetByEntryName("EssLoginPage"); }
		}

		public static string GERPContextConnectionString
		{
			get { return GerpConfig.GetConnectionString("GERPContext"); }
		}

		public static bool CacheMenuInMemory
		{
			get { return Models.Class.ConvertUtility.ConvertOrDefaultStringToBool(GerpConfig.GetByEntryName("CacheMenuInMemory")); }
		}

		public static bool ShowUserListLoginPage
		{
			get { return CompareUtility.IsStringsEqual(GerpConfig.GetByEntryName("ShowUserListLoginPage"), "true"); }
		}

		public static bool WakeupServiceOnPoolStart
		{
			get { return CompareUtility.IsStringsEqual(GerpConfig.GetByEntryName("WakeupServiceOnPoolStart"), "true"); }
		}
        
        public static WhenGoToLoginPageEnum WhenGoToLoginPage
        {
            get
            {
                string whenGoToLoginPageWebConfig = GerpConfig.GetByEntryName("WhenGoToLoginPage");

                if (Models.Class.CompareUtility.IsObjectToStringEqual(whenGoToLoginPageWebConfig, WhenGoToLoginPageEnum.LogOff))
                {
                    return WhenGoToLoginPageEnum.LogOff;
                }
                else if (Models.Class.CompareUtility.IsObjectToStringEqual(whenGoToLoginPageWebConfig, WhenGoToLoginPageEnum.StayAtLogin))
                {
                    return WhenGoToLoginPageEnum.StayAtLogin;
                }
                else if (Models.Class.CompareUtility.IsObjectToStringEqual(whenGoToLoginPageWebConfig, WhenGoToLoginPageEnum.RedirectToHome))
                {
                    return WhenGoToLoginPageEnum.RedirectToHome;
                }
                else
                {
                    // return default
                    return WhenGoToLoginPageEnum.StayAtLogin;
                }
            }
        }

        public enum WhenGoToLoginPageEnum
        {
            LogOff,
            StayAtLogin,
            RedirectToHome
        }

		#endregion
	}
}